using System;
using System.Web.Mvc;

namespace Cooking.UnitTest.Helpers
{
    public static class ActionResultExtensions
    {
        /// <summary>
        /// This is only used for unit testing.  Go ahead and throw an exception, and save me the checking for null on the cast on the other side.
        /// </summary>
        /// <param name="actionResult"></param>
        /// <returns></returns>
        public static ViewResult AsViewResult(this ActionResult actionResult)
        {
            ViewResult vr = actionResult as ViewResult;

            if(vr == null)
            {
                throw new NullReferenceException("Cant convert to ViewResult");
                
            }
            
            return vr;
        }

        /// <summary>
        /// This is only used for unit testing.  Go ahead and throw an exception, and save me the checking for null on the cast on the other side.
        /// </summary>
        /// <param name="actionResult"></param>
        /// <returns></returns>
        public static RedirectToRouteResult AsRedirectToRouteResult(this ActionResult actionResult)
        {
            RedirectToRouteResult rr = actionResult as RedirectToRouteResult;

            if (rr == null)
            {
                throw new NullReferenceException("Can't convert to RedirectToRouteResult");
            }

            return rr;
        }
    }
}